package cz.acies.genea.ui.svg;

import java.util.ArrayList;
import java.util.List;

public class G2MultiObject extends G2Object
{
	private static final long serialVersionUID = 3870865403367023852L;

	protected List<G2Object> objects = new ArrayList<G2Object>();
	
	public G2MultiObject() {
		super();
	}

	public G2MultiObject(List<G2Object> list) {
		super();
		this.objects = list;
	}

	public G2MultiObject addG2Object(G2Object obj) {
		objects.add(obj);
		return this;
	}
	
	public List<G2Object> getObjects() {
		return objects;
	}
	// -----  -----------------------------------------------------------------

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return "G2MultiObject "+objects;
	}

	/* (non-Javadoc)
	 * @see cz.acies.genea.ui.svg.G2Object#getType()
	 */
	@Override
	public String getType() {
		return "path";
	}	

	/**
	 * Metoda vraci retezec - path, pro vykresleni v SVG  
	 * @return
	 */
	public String toSVGPath() {
		String path = "";
		for (G2Object obj : objects) {
			if (obj instanceof G2Line) {
				G2Line line = (G2Line) obj;
				path += "M"+line.x1+","+line.y1+"L"+line.x2+","+line.y2+"";
			} else if (obj instanceof G2Polygon) {
				G2Polygon polygon = (G2Polygon) obj;
				List<G2Point> points = polygon.getPoints();
				path += "M";
				for (int j = 0; j < points.size(); j++) {
					G2Point point = points.get(j);
					if (j > 0) path += "L";
					path += ((int) point.x) + "," + ((int) point.y);
				}
				if (points.size() > 0 && polygon.getDrawAttr().getBackground() != null) {
					G2Point point = points.get(0);
					path += "L" + ((int) point.x) + "," + ((int) point.y);
				}
			} else if (obj instanceof G2Rectangle) {
				G2Rectangle line = (G2Rectangle) obj;
				path += "M"+line.x+","+line.y+"L"+line.width+","+line.height;
			}
		}
		return path;
	}
}
